// CyTargetLinker,
// a Cytoscape plugin to extend biological networks with regulatory interaction
// Copyright 2011-2012 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.cytoscape.cytargetlinker.internal;

import java.io.File;
import java.util.List;

import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;

/**
 * Cytoscape Task - progress bar while
 * the user network is extended
 */
public class MergeTask implements Task {

	private CTLManager linker;
	private List<File> interactionNetworks;
		
	public MergeTask(CTLManager linker, List<File> files) {
		this.linker = linker;
		interactionNetworks = files;
	}
	
	public void halt() {
		// not implemented
	}

	public String getTitle() {
		return "Load Regulatory Interaction Networks ...";
	}

	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {
		taskMonitor.setStatusMessage("Loading...");
		taskMonitor.setProgress(-1.0);
			
		// parses all identifiers from the nodes in the user network
		linker.findUserNetworkIdentifiers();
			
		// parses the matching edges from the regulatory interaction files
		RINHandler.getHandler().loadNetworks(interactionNetworks, linker);
		
		// creates a new network and adds the new nodes and edges
		linker.mergeNetworks();
			
		// creates the result panel
//		linker.getTab().update(linker);
		
		String status = "The following RINs have been loaded\n\n" + linker.getStatusMessage();
			
		linker.applyVisualStyle();
		taskMonitor.setStatusMessage(status);
		taskMonitor.setProgress(100);
	}

	@Override
	public void cancel() {
		// TODO Auto-generated method stub
		
	}
}